/*
 * Copyright (C) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the 'License');
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an 'AS IS' BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef IMAGEKNIFEPRO_IMAGEKNIFE_RENDER_H
#define IMAGEKNIFEPRO_IMAGEKNIFE_RENDER_H

#include <map>
#include "border_option.h"
#include "imageknife_type.h"
#include <arkui/native_node.h>
#include <multimedia/image_framework/image/pixelmap_native.h>
#include <native_drawing/drawing_color_filter.h>

namespace ImageKnifePro {

struct CalculatePosition {
    int left{0};
    int top{0};
    int right{0};
    int bottom{0};
};

class ImageKnifeRender {
public:
    struct DrawingArgs {
        int imageFit = ARKUI_OBJECT_FIT_CONTAIN;
        OH_Drawing_ColorFilter *colorFilter = nullptr;
        std::shared_ptr<BorderOption> border = nullptr;
        EventImage *eventImage = nullptr;
    };
    /**
     * @brief 在CustomNode上绘制一次内容
     * @param event 事件，可获取canvas
     * @param data Pixelmap数据
     * @param args 特殊效果
     */
    void Drawing(ArkUI_NodeCustomEvent *event, OH_PixelmapNative *data, DrawingArgs args);
    
    /**
     * @brief 清空画布
     * @param event 事件，可获取canvas
     */
    void Clear(ArkUI_NodeCustomEvent *event);

private:
    
    /**
     * @brief 计算图片绘制的偏移量，返回rect
     * @param args 绘制信息
     * @param size 组件宽高
     * @param imageSize 图片原始宽高
     * @param borderWidth 描边宽度
     */
    OH_Drawing_Rect *UpdateImageFit(DrawingArgs args, ArkUI_IntSize size, Image_Size imageSize, float borderWidth);
};
}

#endif //IMAGEKNIFEPRO_IMAGEKNIFE_RENDER_H